#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/**
  * @方法: 贪心，双指针
  * @时间复杂度: o(n)
  * @空间复杂度: o(1)
  * @评价: 官方方法，值得学习，腾讯面试题。
*/
int numRescueBoats(vector<int>& people, int limit) {
    sort(people.begin(),people.end());
    int ans = 0;
    int left = 0;
    int right = people.size()-1;
    while(left < right){
        if(people[left] + people[right] > limit){
            right--;
            ans++;
        }else{
            ans++;
            left++;
            right--;
        }
    }
    if(left == right) ans++;
    return ans;
}

int main(){

    cout << "hello world" << endl;
    return 0;
}